<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>format() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>format()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>format()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/displaying/format/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/04-displaying/01-format.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().format();
moment().format(String);
</code></pre>

							</div>
<p>&#x8FD9;&#x662F;&#x6700;&#x7A33;&#x5065;&#x7684;&#x663E;&#x793A;&#x9009;&#x9879;&#x3002;
&#x5B83;&#x63A5;&#x53D7;&#x4E00;&#x4E32;&#x4EE4;&#x724C;&#x5E76;&#x5C06;&#x5176;&#x66FF;&#x6362;&#x4E3A;&#x5176;&#x76F8;&#x5E94;&#x7684;&#x503C;&#x3002;</p>
<pre><code class="language-javascript">moment().format();                                // &quot;2014-09-08T08:02:17-05:00&quot; (ISO 8601&#xFF0C;&#x65E0;&#x5C0F;&#x6570;&#x79D2;&#x949F;)
moment().format(&quot;dddd, MMMM Do YYYY, h:mm:ss a&quot;); // &quot;Sunday, February 14th 2010, 3:25:50 pm&quot;
moment().format(&quot;ddd, hA&quot;);                       // &quot;Sun, 3PM&quot;
moment(&apos;gibberish&apos;).format(&apos;YYYY MM DD&apos;);         // &quot;Invalid date&quot;
</code></pre>
<table class="table table-striped table-bordered">
  <tbody>
    <tr>
      <th></th>
      <th>&#x4EE4;&#x724C;</th>
      <th>&#x8F93;&#x51FA;</th>
    </tr>
    <tr>
      <td><b>&#x6708;&#x4EFD;</b></td>
      <td>M</td>
      <td>1 2 ... 11 12</td>
    </tr>
    <tr>
      <td></td>
      <td>Mo</td>
      <td>1st 2nd ... 11th 12th</td>
    </tr>
    <tr>
      <td></td>
      <td>MM</td>
      <td>01 02 ... 11 12</td>
    </tr>
    <tr>
      <td></td>
      <td>MMM</td>
      <td>Jan Feb ... Nov Dec</td>
    </tr>
    <tr>
      <td></td>
      <td>MMMM</td>
      <td>January February ... November December</td>
    </tr>
    <tr>
      <td><b>&#x5B63;&#x5EA6;</b></td>
      <td>Q</td>
      <td>1 2 3 4</td>
    </tr>
    <tr>
      <td></td>
      <td>Qo</td>
      <td>1st 2nd 3rd 4th</td>
    </tr>
    <tr>
      <td><b>&#x6708;&#x4EFD;&#x7684;&#x65E5;&#x671F;</b></td>
      <td>D</td>
      <td>1 2 ... 30 31</td>
    </tr>
    <tr>
      <td></td>
      <td>Do</td>
      <td>1st 2nd ... 30th 31st</td>
    </tr>
    <tr>
      <td></td>
      <td>DD</td>
      <td>01 02 ... 30 31</td>
    </tr>
    <tr>
      <td><b>&#x5E74;&#x4EFD;&#x7684;&#x65E5;&#x671F;</b></td>
      <td>DDD</td>
      <td>1 2 ... 364 365</td>
    </tr>
    <tr>
      <td></td>
      <td>DDDo</td>
      <td>1st 2nd ... 364th 365th</td>
    </tr>
    <tr>
      <td></td>
      <td>DDDD</td>
      <td>001 002 ... 364 365</td>
    </tr>
    <tr>
      <td><b>&#x661F;&#x671F;&#x51E0;</b></td>
      <td>d</td>
      <td>0 1 ... 5 6</td>
    </tr>
    <tr>
      <td></td>
      <td>do</td>
      <td>0th 1st ... 5th 6th</td>
    </tr>
    <tr>
      <td></td>
      <td>dd</td>
      <td>Su Mo ... Fr Sa</td>
    </tr>
    <tr>
      <td></td>
      <td>ddd</td>
      <td>Sun Mon ... Fri Sat</td>
    </tr>
    <tr>
      <td></td>
      <td>dddd</td>
      <td>Sunday Monday ... Friday Saturday</td>
    </tr>
    <tr>
      <td><b>&#x661F;&#x671F;&#x51E0;&#xFF08;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#xFF09;</b></td>
      <td>e</td>
      <td>0 1 ... 5 6</td>
    </tr>
    <tr>
      <td><b>&#x661F;&#x671F;&#x51E0;&#xFF08;ISO&#xFF09;</b></td>
      <td>E</td>
      <td>1 2 ... 6 7</td>
    </tr>
    <tr>
      <td><b>&#x5E74;&#x4EFD;&#x7684;&#x661F;&#x671F;</b></td>
      <td>w</td>
      <td>1 2 ... 52 53</td>
    </tr>
    <tr>
      <td></td>
      <td>wo</td>
      <td>1st 2nd ... 52nd 53rd</td>
    </tr>
    <tr>
      <td></td>
      <td>ww</td>
      <td>01 02 ... 52 53</td>
    </tr>
    <tr>
      <td><b>&#x5E74;&#x4EFD;&#x7684;&#x661F;&#x671F;&#xFF08;ISO&#xFF09;</b></td>
      <td>W</td>
      <td>1 2 ... 52 53</td>
    </tr>
    <tr>
      <td></td>
      <td>Wo</td>
      <td>1st 2nd ... 52nd 53rd</td>
    </tr>
    <tr>
      <td></td>
      <td>WW</td>
      <td>01 02 ... 52 53</td>
    </tr>
    <tr>
      <td><b>&#x5E74;&#x4EFD;</b></td>
      <td>YY</td>
      <td>70 71 ... 29 30</td>
    </tr>
    <tr>
      <td></td>
      <td>YYYY</td>
      <td>1970 1971 ... 2029 2030</td>
    </tr>
      <tr>
      <td></td>
      <td>Y</td>
      <td>1970 1971 ... 9999 +10000 +10001
        <br>
    &#x6CE8;&#x610F;&#xFF1A;&#x5BF9;&#x4E8E; 9999 &#x5E74;&#x4EE5;&#x540E;&#x7684;&#x65E5;&#x671F;&#xFF0C;&#x8FD9;&#x7B26;&#x5408; ISO 8601 &#x6807;&#x51C6;&#x3002;
      </td>
    </tr>
    <tr>
      <td><b>&#x5468;&#x5E74;</b></td>
      <td>gg</td>
      <td>70 71 ... 29 30</td>
    </tr>
    <tr>
      <td></td>
      <td>gggg</td>
      <td>1970 1971 ... 2029 2030</td>
    </tr>
    <tr>
      <td><b>&#x5468;&#x5E74;&#xFF08;ISO&#xFF09;</b></td>
      <td>GG</td>
      <td>70 71 ... 29 30</td>
    </tr>
    <tr>
      <td></td>
      <td>GGGG</td>
      <td>1970 1971 ... 2029 2030</td>
    </tr>
    <tr>
      <td><b>&#x5B50;&#x5348;&#x7EBF;</b></td>
      <td>A</td>
      <td>AM PM</td>
    </tr>
    <tr>
      <td></td>
      <td>a</td>
      <td>am pm</td>
    </tr>
    <tr>
      <td><b>&#x5C0F;&#x65F6;</b></td>
      <td>H</td>
      <td>0 1 ... 22 23</td>
    </tr>
    <tr>
      <td></td>
      <td>HH</td>
      <td>00 01 ... 22 23</td>
    </tr>
    <tr>
      <td></td>
      <td>h</td>
      <td>1 2 ... 11 12</td>
    </tr>
    <tr>
      <td></td>
      <td>hh</td>
      <td>01 02 ... 11 12</td>
    </tr>
    <tr>
      <td></td>
      <td>k</td>
      <td>1 2 ... 23 24</td>
    </tr>
    <tr>
      <td></td>
      <td>kk</td>
      <td>01 02 ... 23 24</td>
    </tr>
    <tr>
      <td><b>&#x5206;&#x949F;</b></td>
      <td>m</td>
      <td>0 1 ... 58 59</td>
    </tr>
    <tr>
      <td></td>
      <td>mm</td>
      <td>00 01 ... 58 59</td>
    </tr>
    <tr>
      <td><b>&#x79D2;&#x949F;</b></td>
      <td>s</td>
      <td>0 1 ... 58 59</td>
    </tr>
    <tr>
      <td></td>
      <td>ss</td>
      <td>00 01 ... 58 59</td>
    </tr>
    <tr>
      <td><b>&#x5C0F;&#x6570;&#x79D2;&#x949F;</b></td>
      <td>S</td>
      <td>0 1 ... 8 9</td>
    </tr>
    <tr>
      <td></td>
      <td>SS</td>
      <td>00 01 ... 98 99</td>
    </tr>
    <tr>
      <td></td>
      <td>SSS</td>
      <td>000 001 ... 998 999</td>
    </tr>
    <tr>
      <td></td>
      <td>SSSS ... SSSSSSSSS</td>
      <td>000[0..] 001[0..] ... 998[0..] 999[0..]</td>
    </tr>
    <tr>
      <td><b>&#x65F6;&#x533A;</b></td>
      <td>z or zz</td>
      <td>
        EST CST ... MST PST
        <br>
    &#x6CE8;&#x610F;&#xFF1A;&#x4ECE; <b>1.6.0</b> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;z/zz &#x683C;&#x5F0F;&#x7684;&#x4EE4;&#x724C;&#x5DF2;&#x4ECE;&#x666E;&#x901A;&#x7684; moment &#x5BF9;&#x8C61;&#x4E2D;&#x5F03;&#x7528;&#x3002;
    <a href="javascript:window.open('https://github.com/moment/moment/issues/162');" target="_blank" rel="nofollow">&#x5728;&#x6B64;&#x5904;&#x4E86;&#x89E3;&#x66F4;&#x591A;&#x4FE1;&#x606F;</a>&#x3002;
    &#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x5C06;&#x7279;&#x5B9A;&#x65F6;&#x533A;&#x4E0E; moment-timezone &#x63D2;&#x4EF6;&#x4E00;&#x8D77;&#x4F7F;&#x7528;&#xFF0C;&#x5B83;&#x4EEC;&#x4F1A;&#x8D77;&#x4F5C;&#x7528;&#x3002;
      </td>
    </tr>
    <tr>
      <td></td>
      <td>Z</td>
      <td>-07:00 -06:00 ... +06:00 +07:00</td>
    </tr>
    <tr>
      <td></td>
      <td>ZZ</td>
      <td>
        -0700 -0600 ... +0600 +0700
      </td>
    </tr>
    <tr>
      <td><b>Unix &#x65F6;&#x95F4;&#x6233;</b></td>
      <td>X</td>
      <td>1360013296</td>
    </tr>
    <tr>
      <td><b>Unix &#x6BEB;&#x79D2;&#x65F6;&#x95F4;&#x6233;</b></td>
      <td>x</td>
      <td>1360013296123</td>
    </tr>
  </tbody>
</table>
<p><code>X</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.0.0</strong>&#x3002;</p>
<p><code>e E gg gggg GG GGGG</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.1.0</strong>&#x3002;</p>
<p><code>x</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.8.4</strong>&#x3002;</p>
<p><code>SSSS</code> &#x81F3; <code>SSSSSSSSS</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.10.5</strong>&#x3002;
&#x5B83;&#x4EEC;&#x4F1A;&#x663E;&#x793A; 3 &#x4F4D;&#x6709;&#x6548;&#x6570;&#x5B57;&#xFF0C;&#x5176;&#x4F59;&#x90E8;&#x5206;&#x7528;&#x96F6;&#x586B;&#x5145;&#x3002;</p>
<p><code>k</code> &#x548C; <code>kk</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.13.0</strong>&#x3002;</p>
<h4>&#x672C;&#x5730;&#x5316;&#x683C;&#x5F0F;</h4>
<p>&#x7531;&#x4E8E;&#x9996;&#x9009;&#x7684;&#x683C;&#x5F0F;&#x4F1A;&#x6839;&#x636E;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x800C;&#x6709;&#x6240;&#x4E0D;&#x540C;&#xFF0C;&#x56E0;&#x6B64;&#x6709;&#x4E00;&#x4E9B;&#x4EE4;&#x724C;&#x53EF;&#x7528;&#x4E8E;&#x6839;&#x636E;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x683C;&#x5F0F; moment&#x3002;</p>
<p>&#x540C;&#x4E00;&#x683C;&#x5F0F;&#x6709;&#x5927;&#x5C0F;&#x5199;&#x53D8;&#x4F53;&#x3002;
&#x5C0F;&#x5199;&#x7248;&#x672C;&#x65E8;&#x5728;&#x4F5C;&#x4E3A;&#x5927;&#x5199;&#x7248;&#x672C;&#x7684;&#x7B80;&#x5316;&#x7248;&#x672C;&#x3002;</p>
<table class="table table-striped table-bordered">
  <tbody>
    <tr>
      <td><b>&#x65F6;&#x95F4;</b></td>
      <td>LT</td>
      <td>8:30 PM</td>
    </tr>
    <tr>
      <td><b>&#x5E26;&#x79D2;&#x949F;&#x7684;&#x65F6;&#x95F4;</b></td>
      <td>LTS</td>
      <td>8:30:25 PM</td>
    </tr>
    <tr>
      <td><b>&#x6708;&#x4EFD;&#x6570;&#x5B57;&#xFF0C;&#x6708;&#x4EFD;&#x65E5;&#x671F;&#xFF0C;&#x5E74;&#x4EFD;</b></td>
      <td>L</td>
      <td>09/04/1986</td>
    </tr>
    <tr>
      <td></td>
      <td>l</td>
      <td>9/4/1986</td>
    </tr>
    <tr>
      <td><b>&#x6708;&#x4EFD;&#x540D;&#x79F0;&#xFF0C;&#x6708;&#x4EFD;&#x65E5;&#x671F;&#xFF0C;&#x5E74;&#x4EFD;</b></td>
      <td>LL</td>
      <td>September 4, 1986</td>
    </tr>
    <tr>
      <td></td>
      <td>ll</td>
      <td>Sep 4, 1986</td>
    </tr>
    <tr>
      <td><b>&#x6708;&#x4EFD;&#x540D;&#x79F0;&#xFF0C;&#x6708;&#x4EFD;&#x65E5;&#x671F;&#xFF0C;&#x5E74;&#x4EFD;&#xFF0C;&#x65F6;&#x95F4;</b></td>
      <td>LLL</td>
      <td>September 4, 1986 8:30 PM</td>
    </tr>
    <tr>
      <td></td>
      <td>lll</td>
      <td>Sep 4, 1986 8:30 PM</td>
    </tr>
    <tr>
      <td><b>&#x6708;&#x4EFD;&#x540D;&#x79F0;&#xFF0C;&#x6708;&#x4EFD;&#x65E5;&#x671F;&#xFF0C;&#x661F;&#x671F;&#x51E0;&#xFF0C;&#x5E74;&#x4EFD;&#xFF0C;&#x65F6;&#x95F4;</b></td>
      <td>LLLL</td>
      <td>Thursday, September 4, 1986 8:30 PM</td>
    </tr>
    <tr>
      <td></td>
      <td>llll</td>
      <td>Thu, Sep 4, 1986 8:30 PM</td>
    </tr>
  </tbody>
</table>
<p><code>l ll lll llll</code> &#x5728; <strong>2.0.0</strong> &#x4E2D;&#x53EF;&#x7528;&#x3002;
<code>LTS</code> &#x65B0;&#x589E;&#x4E8E; <strong>2.8.4</strong>&#x3002;</p>
<h4>&#x8F6C;&#x4E49;&#x5B57;&#x7B26;</h4>
<p>&#x8981;&#x8F6C;&#x4E49;&#x683C;&#x5F0F;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x5B57;&#x7B26;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x5B57;&#x7B26;&#x5305;&#x88C5;&#x5728;&#x65B9;&#x62EC;&#x53F7;&#x4E2D;&#x3002;</p>
<pre><code class="language-javascript">moment().format(&apos;[&#x4ECA;&#x5929;] dddd&apos;); // &apos;&#x4ECA;&#x5929; Sunday&apos;
</code></pre>
<h4>&#x4E0E; LDML &#x7684;&#x5F02;&#x540C;</h4>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x867D;&#x7136;&#x8FD9;&#x4E9B;&#x65E5;&#x671F;&#x683C;&#x5F0F;&#x4E0E; LDML &#x65E5;&#x671F;&#x683C;&#x5F0F;&#x975E;&#x5E38;&#x76F8;&#x4F3C;&#xFF0C;&#x4F46;&#x662F;&#x5728;&#x6708;&#x4EFD;&#x7684;&#x65E5;&#x671F;&#x3001;&#x5E74;&#x4EFD;&#x7684;&#x65E5;&#x671F;&#x3001;&#x661F;&#x671F;&#x51E0;&#x7B49;&#x65B9;&#x9762;&#x5B58;&#x5728;&#x4E00;&#x4E9B;&#x7EC6;&#x5FAE;&#x7684;&#x5DEE;&#x5F02;&#x3002;</p>
<p>&#x6709;&#x5173;&#x8DE8;&#x4E0D;&#x540C;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x7684;&#x4E00;&#x4E9B;&#x4E0D;&#x540C;&#x7684;&#x65E5;&#x671F;&#x683C;&#x5F0F;&#x4EE4;&#x724C;&#x7684;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;&#xFF0C;&#x53C2;&#x9605;<a href="javascript:window.open('http://nodejs.cn/s/HG8t7d');" target="_blank" rel="nofollow">&#x65E5;&#x671F;&#x683C;&#x5F0F;&#x4EE4;&#x724C;&#x7684;&#x56FE;&#x8868;</a>&#x3002;</p>
<h4>&#x683C;&#x5F0F;&#x5316;&#x901F;&#x5EA6;</h4>
<p>&#x8981;&#x4E0E;&#x5176;&#x4ED6;&#x5E93;&#x6BD4;&#x8F83; Moment.js &#x7684;&#x683C;&#x5F0F;&#x5316;&#x901F;&#x5EA6;&#xFF0C;&#x8BF7;&#x5DEE;&#x5F02;<a href="javascript:window.open('http://nodejs.cn/s/tCdrub');" target="_blank" rel="nofollow">&#x4E0E;&#x5176;&#x4ED6;&#x5E93;&#x7684;&#x6BD4;&#x8F83;</a>&#x3002;</p>
<h4>&#x5176;&#x4ED6;&#x4EE4;&#x724C;</h4>
<p>&#x5982;&#x679C;&#x66F4;&#x4E60;&#x60EF;&#x4F7F;&#x7528; strftime &#x800C;&#x4E0D;&#x662F;&#x7C7B;&#x4F3C; LDML &#x7684;&#x89E3;&#x6790;&#x4EE4;&#x724C;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Ben Oakes &#x7684;&#x63D2;&#x4EF6; <a href="javascript:window.open('http://nodejs.cn/s/TVgJ7M');" target="_blank" rel="nofollow">benjaminoakes/moment-strftime</a>&#x3002;</p>
<h4>&#x9ED8;&#x8BA4;&#x7684;&#x683C;&#x5F0F;</h4>
<p>&#x4E0D;&#x4F7F;&#x7528;&#x683C;&#x5F0F;&#x8C03;&#x7528; <code>moment#format</code> &#x5C06;&#x4F1A;&#x9ED8;&#x8BA4;&#x4E3A; <code>moment.defaultFormat</code>&#x3002;
&#x5F00;&#x7BB1;&#x5373;&#x7528;&#x7684; <code>moment.defaultFormat</code> &#x662F; ISO8601 &#x683C;&#x5F0F; <code>YYYY-MM-DDTHH:mm:ssZ</code>&#x3002;</p>
<p>&#x4ECE; <strong>2.13.0</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x5F53;&#x5728; UTC &#x6A21;&#x5F0F;&#x4E2D;&#x65F6;&#xFF0C;&#x9ED8;&#x8BA4;&#x7684;&#x683C;&#x5F0F;&#x7531; <code>moment.defaultFormatUtc</code> &#x7BA1;&#x7406;&#x7684;&#xFF0C;&#x5176;&#x683C;&#x5F0F;&#x662F; <code>YYYY-MM-DDTHH:mm:ss[Z]</code>&#x3002;
&#x8FD9;&#x4F1A;&#x8FD4;&#x56DE; <code>Z</code> &#x4F5C;&#x4E3A;&#x504F;&#x79FB;&#x91CF;&#xFF0C;&#x800C;&#x4E0D;&#x662F; <code>+00:00</code>&#x3002;</p>
<p>&#x5728;&#x67D0;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x672C;&#x5730;&#x65F6;&#x533A;&#xFF08;&#x4F8B;&#x5982; <code>Atlantic/Reykjavik</code>&#xFF09;&#x53EF;&#x80FD;&#x5177;&#x6709;&#x96F6;&#x504F;&#x79FB;&#x91CF;&#xFF0C;&#x4E14;&#x5C06;&#x4F1A;&#x88AB;&#x89C6;&#x4E3A; UTC&#x3002;
&#x5728;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5C06; <code>moment.defaultFormat</code> &#x548C; <code>moment.defaultFormatUtc</code> &#x8BBE;&#x7F6E;&#x4E3A;&#x4F7F;&#x7528;&#x76F8;&#x540C;&#x7684;&#x683C;&#x5F0F;&#x53EF;&#x80FD;&#x5F88;&#x6709;&#x7528;&#x3002;</p>
<p>&#x66F4;&#x6539; <code>moment.defaultFormat</code> &#x7684;&#x503C;&#x4EC5;&#x4F1A;&#x5F71;&#x54CD;&#x683C;&#x5F0F;&#x5316;&#xFF0C;&#x800C;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x89E3;&#x6790;&#x3002;
&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="language-javascript">moment.defaultFormat = &quot;DD.MM.YYYY HH:mm&quot;;
// &#x4F7F;&#x7528; .toDate() &#x89E3;&#x6790;&#x3002;
moment(&apos;20.07.2018 09:19&apos;).toDate() // Invalid date
// &#x4F7F;&#x7528;&#x65B0;&#x7684; defaultFormat &#x683C;&#x5F0F;&#x5316;&#x65E5;&#x671F;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x7136;&#x540E;&#x89E3;&#x6790;&#x3002;
moment(&apos;20.07.2018 09:19&apos;, moment.defaultFormat).toDate() // Fri Jul 20 2018 09:19:00 GMT+0300
</code></pre>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().format();
moment().format(String);
</code></pre>

							</div>
<p>This is the most robust display option. It takes a string of tokens and replaces them with their corresponding values.</p>
<pre><code class="language-javascript">moment().format();                                // &quot;2014-09-08T08:02:17-05:00&quot; (ISO 8601, no fractional seconds)
moment().format(&quot;dddd, MMMM Do YYYY, h:mm:ss a&quot;); // &quot;Sunday, February 14th 2010, 3:25:50 pm&quot;
moment().format(&quot;ddd, hA&quot;);                       // &quot;Sun, 3PM&quot;
moment(&apos;gibberish&apos;).format(&apos;YYYY MM DD&apos;);         // &quot;Invalid date&quot;
</code></pre>
<table class="table table-striped table-bordered">
  <tbody>
    <tr>
      <th></th>
      <th>Token</th>
      <th>Output</th>
    </tr>
    <tr>
      <td><b>Month</b></td>
      <td>M</td>
      <td>1 2 ... 11 12</td>
    </tr>
    <tr>
      <td></td>
      <td>Mo</td>
      <td>1st 2nd ... 11th 12th</td>
    </tr>
    <tr>
      <td></td>
      <td>MM</td>
      <td>01 02 ... 11 12</td>
    </tr>
    <tr>
      <td></td>
      <td>MMM</td>
      <td>Jan Feb ... Nov Dec</td>
    </tr>
    <tr>
      <td></td>
      <td>MMMM</td>
      <td>January February ... November December</td>
    </tr>
    <tr>
      <td><b>Quarter</b></td>
      <td>Q</td>
      <td>1 2 3 4</td>
    </tr>
    <tr>
      <td></td>
      <td>Qo</td>
      <td>1st 2nd 3rd 4th</td>
    </tr>
    <tr>
      <td><b>Day of Month</b></td>
      <td>D</td>
      <td>1 2 ... 30 31</td>
    </tr>
    <tr>
      <td></td>
      <td>Do</td>
      <td>1st 2nd ... 30th 31st</td>
    </tr>
    <tr>
      <td></td>
      <td>DD</td>
      <td>01 02 ... 30 31</td>
    </tr>
    <tr>
      <td><b>Day of Year</b></td>
      <td>DDD</td>
      <td>1 2 ... 364 365</td>
    </tr>
    <tr>
      <td></td>
      <td>DDDo</td>
      <td>1st 2nd ... 364th 365th</td>
    </tr>
    <tr>
      <td></td>
      <td>DDDD</td>
      <td>001 002 ... 364 365</td>
    </tr>
    <tr>
      <td><b>Day of Week</b></td>
      <td>d</td>
      <td>0 1 ... 5 6</td>
    </tr>
    <tr>
      <td></td>
      <td>do</td>
      <td>0th 1st ... 5th 6th</td>
    </tr>
    <tr>
      <td></td>
      <td>dd</td>
      <td>Su Mo ... Fr Sa</td>
    </tr>
    <tr>
      <td></td>
      <td>ddd</td>
      <td>Sun Mon ... Fri Sat</td>
    </tr>
    <tr>
      <td></td>
      <td>dddd</td>
      <td>Sunday Monday ... Friday Saturday</td>
    </tr>
    <tr>
      <td><b>Day of Week (Locale)</b></td>
      <td>e</td>
      <td>0 1 ... 5 6</td>
    </tr>
    <tr>
      <td><b>Day of Week (ISO)</b></td>
      <td>E</td>
      <td>1 2 ... 6 7</td>
    </tr>
    <tr>
      <td><b>Week of Year</b></td>
      <td>w</td>
      <td>1 2 ... 52 53</td>
    </tr>
    <tr>
      <td></td>
      <td>wo</td>
      <td>1st 2nd ... 52nd 53rd</td>
    </tr>
    <tr>
      <td></td>
      <td>ww</td>
      <td>01 02 ... 52 53</td>
    </tr>
    <tr>
      <td><b>Week of Year (ISO)</b></td>
      <td>W</td>
      <td>1 2 ... 52 53</td>
    </tr>
    <tr>
      <td></td>
      <td>Wo</td>
      <td>1st 2nd ... 52nd 53rd</td>
    </tr>
    <tr>
      <td></td>
      <td>WW</td>
      <td>01 02 ... 52 53</td>
    </tr>
    <tr>
      <td><b>Year</b></td>
      <td>YY</td>
      <td>70 71 ... 29 30</td>
    </tr>
    <tr>
      <td></td>
      <td>YYYY</td>
      <td>1970 1971 ... 2029 2030</td>
    </tr>
      <tr>
      <td></td>
      <td>Y</td>
      <td>1970 1971 ... 9999 +10000 +10001
        <br>
        <b>Note:</b> This complies with the ISO 8601 standard for dates past the year 9999
      </td>
    </tr>
    <tr>
      <td><b>Week Year</b></td>
      <td>gg</td>
      <td>70 71 ... 29 30</td>
    </tr>
    <tr>
      <td></td>
      <td>gggg</td>
      <td>1970 1971 ... 2029 2030</td>
    </tr>
    <tr>
      <td><b>Week Year (ISO)</b></td>
      <td>GG</td>
      <td>70 71 ... 29 30</td>
    </tr>
    <tr>
      <td></td>
      <td>GGGG</td>
      <td>1970 1971 ... 2029 2030</td>
    </tr>
    <tr>
      <td><b>AM/PM</b></td>
      <td>A</td>
      <td>AM PM</td>
    </tr>
    <tr>
      <td></td>
      <td>a</td>
      <td>am pm</td>
    </tr>
    <tr>
      <td><b>Hour</b></td>
      <td>H</td>
      <td>0 1 ... 22 23</td>
    </tr>
    <tr>
      <td></td>
      <td>HH</td>
      <td>00 01 ... 22 23</td>
    </tr>
    <tr>
      <td></td>
      <td>h</td>
      <td>1 2 ... 11 12</td>
    </tr>
    <tr>
      <td></td>
      <td>hh</td>
      <td>01 02 ... 11 12</td>
    </tr>
    <tr>
      <td></td>
      <td>k</td>
      <td>1 2 ... 23 24</td>
    </tr>
    <tr>
      <td></td>
      <td>kk</td>
      <td>01 02 ... 23 24</td>
    </tr>
    <tr>
      <td><b>Minute</b></td>
      <td>m</td>
      <td>0 1 ... 58 59</td>
    </tr>
    <tr>
      <td></td>
      <td>mm</td>
      <td>00 01 ... 58 59</td>
    </tr>
    <tr>
      <td><b>Second</b></td>
      <td>s</td>
      <td>0 1 ... 58 59</td>
    </tr>
    <tr>
      <td></td>
      <td>ss</td>
      <td>00 01 ... 58 59</td>
    </tr>
    <tr>
      <td><b>Fractional Second</b></td>
      <td>S</td>
      <td>0 1 ... 8 9</td>
    </tr>
    <tr>
      <td></td>
      <td>SS</td>
      <td>00 01 ... 98 99</td>
    </tr>
    <tr>
      <td></td>
      <td>SSS</td>
      <td>000 001 ... 998 999</td>
    </tr>
    <tr>
      <td></td>
      <td>SSSS ... SSSSSSSSS</td>
      <td>000[0..] 001[0..] ... 998[0..] 999[0..]</td>
    </tr>
    <tr>
      <td><b>Time Zone</b></td>
      <td>z or zz</td>
      <td>
        EST CST ... MST PST
        <br>
        <b>Note:</b> as of <b>1.6.0</b>, the z/zz format tokens have been deprecated from plain moment objects. <a href="javascript:window.open('https://github.com/moment/moment/issues/162');" target="_blank" rel="nofollow">Read more about it here.</a>
        However, they *do* work if you are using a specific time zone with the moment-timezone addon.
      </td>
    </tr>
    <tr>
      <td></td>
      <td>Z</td>
      <td>-07:00 -06:00 ... +06:00 +07:00</td>
    </tr>
    <tr>
      <td></td>
      <td>ZZ</td>
      <td>
        -0700 -0600 ... +0600 +0700
      </td>
    </tr>
    <tr>
      <td><b>Unix Timestamp</b></td>
      <td>X</td>
      <td>1360013296</td>
    </tr>
    <tr>
      <td><b>Unix Millisecond Timestamp</b></td>
      <td>x</td>
      <td>1360013296123</td>
    </tr>
  </tbody>
</table>
<p><code>X</code> was added in <strong>2.0.0</strong>.</p>
<p><code>e E gg gggg GG GGGG</code> were added in <strong>2.1.0</strong>.</p>
<p><code>x</code> was added in <strong>2.8.4</strong>.</p>
<p><code>SSSS</code> to <code>SSSSSSSSS</code> were added in <strong>2.10.5</strong>. They display 3 significant
digits and the rest is filled with zeros.</p>
<p><code>k</code> and <code>kk</code> were added in <strong>2.13.0</strong>.</p>
<h4>Localized formats</h4>
<p>Because preferred formatting differs based on locale, there are a few tokens that can be used to format a moment based on its locale.</p>
<p>There are upper and lower case variations on the same formats. The lowercase version is intended to be the shortened version of its uppercase counterpart.</p>
<table class="table table-striped table-bordered">
  <tbody>
    <tr>
      <td><b>Time</b></td>
      <td>LT</td>
      <td>8:30 PM</td>
    </tr>
    <tr>
      <td><b>Time with seconds</b></td>
      <td>LTS</td>
      <td>8:30:25 PM</td>
    </tr>
    <tr>
      <td><b>Month numeral, day of month, year</b></td>
      <td>L</td>
      <td>09/04/1986</td>
    </tr>
    <tr>
      <td></td>
      <td>l</td>
      <td>9/4/1986</td>
    </tr>
    <tr>
      <td><b>Month name, day of month, year</b></td>
      <td>LL</td>
      <td>September 4, 1986</td>
    </tr>
    <tr>
      <td></td>
      <td>ll</td>
      <td>Sep 4, 1986</td>
    </tr>
    <tr>
      <td><b>Month name, day of month, year, time</b></td>
      <td>LLL</td>
      <td>September 4, 1986 8:30 PM</td>
    </tr>
    <tr>
      <td></td>
      <td>lll</td>
      <td>Sep 4, 1986 8:30 PM</td>
    </tr>
    <tr>
      <td><b>Month name, day of month, day of week, year, time</b></td>
      <td>LLLL</td>
      <td>Thursday, September 4, 1986 8:30 PM</td>
    </tr>
    <tr>
      <td></td>
      <td>llll</td>
      <td>Thu, Sep 4, 1986 8:30 PM</td>
    </tr>
  </tbody>
</table>
<p><code>l ll lll llll</code> are available in <strong>2.0.0</strong>.
<code>LTS</code> was added in <strong>2.8.4</strong>.</p>
<h4>Escaping characters</h4>
<p>To escape characters in format strings, you can wrap the characters in square brackets.</p>
<pre><code class="language-javascript">moment().format(&apos;[today] dddd&apos;); // &apos;today Sunday&apos;
</code></pre>
<h4>Similarities and differences with LDML</h4>
<p><strong>Note:</strong> While these date formats are very similar to LDML date formats, there are a few minor differences regarding day of month, day of year, and day of week.</p>
<p>For a breakdown of a few different date formatting tokens across different locales, see <a href="javascript:window.open('https://docs.google.com/spreadsheet/ccc?key=0AtgZluze7WMJdDBOLUZfSFIzenIwOHNjaWZoeGFqbWc&amp;amp;hl=en_US#gid=0');" target="_blank" rel="nofollow">this chart of date formatting tokens.</a></p>
<h4>Formatting speed</h4>
<p>To compare Moment.js formatting speed against other libraries, check out <a href="javascript:window.open('https://jsperf.com/date-formatting/49');" target="_blank" rel="nofollow">this comparison against other libraries</a>.</p>
<h4>Other tokens</h4>
<p>If you are more comfortable working with strftime instead of LDML-like parsing tokens, you can use Ben Oakes&apos; plugin. <a href="javascript:window.open('https://github.com/benjaminoakes/moment-strftime');" target="_blank" rel="nofollow">benjaminoakes/moment-strftime</a>.</p>
<h4>Default format</h4>
<p>Calling <code>moment#format</code> without a format will default to <code>moment.defaultFormat</code>. Out of the box, <code>moment.defaultFormat</code> is the ISO8601 format <code>YYYY-MM-DDTHH:mm:ssZ</code>.</p>
<p>As of version <strong>2.13.0</strong>, when in UTC mode, the default format is governed by <code>moment.defaultFormatUtc</code> which is in the format <code>YYYY-MM-DDTHH:mm:ss[Z]</code>. This returns <code>Z</code> as the offset, instead of <code>+00:00</code>.</p>
<p>In certain instances, a local timezone (such as <code>Atlantic/Reykjavik</code>) may have a zero offset, and will be considered to be UTC. In such cases, it may be useful to set <code>moment.defaultFormat</code> and <code>moment.defaultFormatUtc</code> to use the same formatting.</p>
<p>Changing the value of <code>moment.defaultFormat</code> will only affect formatting, and will not affect parsing. for example:</p>
<pre><code class="language-javascript">moment.defaultFormat = &quot;DD.MM.YYYY HH:mm&quot;;
// parse with .toDate()
moment(&apos;20.07.2018 09:19&apos;).toDate() // Invalid date
// format the date string with the new defaultFormat then parse
moment(&apos;20.07.2018 09:19&apos;, moment.defaultFormat).toDate() // Fri Jul 20 2018 09:19:00 GMT+0300
</code></pre>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>